home *** CD-ROM | disk | FTP | other *** search
- /**************************************************************************/
- /* */
- /* LabelMerge v1.02 */
- /* */
- /* */
- /* Copyright ©1996-1997 by Dick Whiting */
- /* */
- /*========================================================================*/
- /* */
- /* */
- /* Report bugs, comments, etc. to: */
- /* */
- /* Dick Whiting <dwhiting@europa.com> */
- /* */
- /* 04 August 1997 */
- /* */
- /**************************************************************************/
- /*
- $VER: 1.02 Copyright ©1997 by Dick Whiting
- $AUTHOR: Dick Whiting
- $DESCRIPTION: Create mail-merged labels, postcards, etc.
- */
-
- OPTIONS RESULTS
-
- /* Make sure rexx support is opened */
- IF ~SHOW('L','rexxsupport.library') THEN
- CALL ADDLIB('rexxsupport.library',0,-30)
-
- ADDRESS 'PAGESTREAM'
-
-
- /**************************************************************************/
- /* */
- /* You may change these variables if necessary */
- /* */
- /*========================================================================*/
- /* */
- /* prefsfile is used to set the default intitial options, you CAN change */
- /* this to point to ANY valid path/filename you wish. */
- /* The path/filename MUST BE ENCLOSED IN QUOTES */
- /* */
- /**************************************************************************/
-
- prefsfile="PageStream3:scripts/TemplateData/LabelMerge.prefs"
-
- /**************************************************************************/
- /* */
- /* Main Logic: */
- /* */
- /* 1) Setup Preferences - use internal defaults if no prefsfile */
- /* 2) Get Data file, Template file, etc. using requester */
- /* 3) Calculate number of text blocks, pages, etc. needed */
- /* 4) Build each text block with the inserted values */
- /* 5) Return to user for visual inspection and printing */
- /* */
- /* CANCELS and errors are handled by jumping to end of each routine if */
- /* the doneselecting flag is set. Did it this way to avoid a zillion */
- /* exit statements scattered throughout the code. */
- /* */
- /**************************************************************************/
-
- CALL Init
- CALL ReadPrefs
- CALL GetUserInfo
- CALL LoadPGS
- CALL OpenData
- CALL GetGuides
- CALL BldCoords
- do while doneselecting=0
- CALL SelectModel
- CALL BldBoxes
- end
-
- exit 0
-
- /**************************************************************************/
- /* */
- /* Show a nice:) requester for the user. Get the information needed. */
- /* The initial display includes any values set in the prefs file. */
- /* */
- /**************************************************************************/
- GetUserInfo:
-
- allocarexxrequester '"Label Merge Setup"' 400 200
- handle.req=result
-
- allocarexxlist
- delimlist=result
- do i=1 to delimstem.0 /* load delimiter char list */
- addarexxlist delimlist delimstem.i
- end
-
- allocarexxlist
- vindlist=result
- do i=1 to vindstem.0 /* load variable indicators */
- addarexxlist vindlist vindstem.i||'variable'||vindstem.i.1
- end
-
- edge=10
- leftedge=145
- cyclen=145
- checklen=10
- getinfomsg='Select Options and Files - OK when done'
- getinfo=1 /* control of requester loop */
-
- addarexxgadget handle.req EXIT 10 180 70 label "_OK"
- okhandle=result
-
- addarexxgadget handle.req EXIT 320 180 70 label "_Cancel"
- cancelhandle=result
-
- addarexxgadget handle.req CYCLE leftedge 10 cyclen label '"Field Delimiter:"' BORDER raised LIST delimlist CURRENT defaultdelim
- delimhandle=result
-
- addarexxgadget handle.req CYCLE leftedge 25 cyclen label '"Variable Format:"' BORDER raised LIST vindlist CURRENT defaultvind
- varhandle=result
-
- addarexxgadget handle.req CHECKBOX leftedge 40 checklen label '"Automatic Mode:"' labelpos LEFT BORDER raised CHECKED defaultmode
- modehandle=result
-
- addarexxgadget handle.req CHECKBOX leftedge 55 checklen label '"Watch Me Work:"' labelpos LEFT BORDER raised CHECKED defaultwatchme
- refrhandle=result
-
- addarexxgadget handle.req STRING edge+300 55 50 label '"Fuzziness"' labelpos LEFT BORDER raised STRING pctvar
- pcthandle=result
-
- addarexxgadget handle.req STRING edge 95 350 label '"PAGESTREAM file:"' labelpos ABOVELEFT BORDER raised STRING templatefile
- temphandle=result
-
- addarexxgadget handle.req EXIT edge+355 95 10 label "?"
- gettemphandle=result
-
- addarexxgadget handle.req STRING edge 125 350 label '"ASCII data file:"' labelpos ABOVELEFT BORDER raised STRING datafile
- datahandle=result
-
- addarexxgadget handle.req EXIT edge+355 125 10 label "?"
- getdatahandle=result
-
- addarexxgadget handle.req TEXT edge 155 380 label '"Label Merge Messages:"' labelpos ABOVELEFT BORDER text STRING '"'getinfomsg'"'
- infomsghandle=result
-
- addarexxgadget handle.req EXIT 165 180 70 label "_Help"
- helphandle=result
-
-
- do while getinfo=1
-
- doarexxrequester handle.req
- action=result
-
- getarexxgadget handle.req delimhandle current
- delimchar=result
-
- getarexxgadget handle.req varhandle current
- varchar=result
-
- getarexxgadget handle.req modehandle checked
- modechar=result
-
- getarexxgadget handle.req refrhandle checked
- refrchar=result
-
- getarexxgadget handle.req datahandle string
- datachar=result
- if datachar~=datafile then datafile=datachar
-
- getarexxgadget handle.req pcthandle string
- pctchar=result
-
- getarexxgadget handle.req temphandle string
- tempchar=result
- if tempchar~=templatefile then templatefile=tempchar
-
- getinfomsg='Verify Options and Files - OK when ready'
- setarexxgadget handle.req infomsghandle STRING "'"getinfomsg"'"
-
- select
- when action=okhandle then do /* user is all done (maybe) */
- i=varchar+1 /* needs to base of 1 not 0 */
- lvind=vindstem.i /* left variable indicator */
- rvind=vindstem.i.1 /* right variable indicator */
- i=delimchar+1 /* needs to base of 1 not 0 */
- datadelim=delimstem.i.1 /* set data delimiter charact */
- if modechar=1 then mode='AUTO'
- else mode='MANUAL'
- getinfo=0 /* quit loop (maybe) */
- if datafile='' then do /* no data file specified */
- getinfomsg='You must select an ASCII data file'
- setarexxgadget handle.req infomsghandle STRING "'"getinfomsg"'"
- getinfo=1 /* continue loop */
- end
- if templatefile='' then do /* no PGS template specified */
- getinfomsg='You must select a PageStream template file'
- setarexxgadget handle.req infomsghandle STRING "'"getinfomsg"'"
- getinfo=1 /* continue loop */
- end
- if pctchar~='' & datatype(pctchar,'N'),
- & pctchar <= .5 & pctchar >= 0 then pctvar=pctchar
- else do
- getinfomsg='Fuzziness must be between 0 and .5 inclusive'
- setarexxgadget handle.req pcthandle STRING pctvar
- setarexxgadget handle.req infomsghandle STRING "'"getinfomsg"'"
- getinfo=1 /* continue loop */
- end
- end
- when action=getdatahandle then do
- getfile title "'Select the ASCII file'" PATH datapath LOAD POSBUTTON "Ok" NEGBUTTON "Cancel"
- if rc=0 then do
- datafile=result
- setarexxgadget handle.req datahandle STRING "'"datafile"'"
- end
- end
- when action=gettemphandle then do
- getfile title "'Select the PAGESTREAM file'" PATH templatepath LOAD POSBUTTON "Ok" NEGBUTTON "Cancel"
- if rc=0 then do
- templatefile=result
- setarexxgadget handle.req temphandle STRING "'"templatefile"'"
- end
- end
- when action=cancelhandle then do
- doneselecting=1 /* user wants to quit */
- getinfo=0
- end
- otherwise do /* should be the help button */
- Call HelpDisplay
- end
- end /* matches select */
- end /* matches do getinfo */
-
- freearexxrequester handle.req
- freearexxlist delimlist
- freearexxlist vindlist
-
- Return
-
- /**************************************************************************/
- /* Get information about pagesize, margins, and guides */
- /* Locate ALL guides and store in arrays */
- /* Build array describing all possible text block areas and mark the ones */
- /* that are most likely actual label/form text areas. */
- /**************************************************************************/
- GetGuides:
-
- if doneselecting=1 then signal GetGuidesExit /* skip all processing */
-
- 'getdimensions diminfo' /* get size of paper & orient.*/
-
- orient=diminfo.orientation /* check orientation of page */
-
- if orient='PORTRAIT' then do
- pgwidth=diminfo.width /* width of page */
- pgheight=diminfo.height /* height of page */
- end
- else do /* swap them */
- pgwidth=diminfo.height /* width of page */
- pgheight=diminfo.width /* height of page */
- end
-
- 'getmarginguides marinfo' /* get margin guide info */
- lmar=marinfo.inside /* left edge of first column */
- rmar=marinfo.outside /* right edge of last column */
- tmar=marinfo.top /* top margin */
- bmar=marinfo.bottom /* bottom margin */
-
- 'getcolumnguides cinfo' /* how many columns and gutter*/
- colcnt=cinfo.count /* number of cols */
- cgut=cinfo.gutter /* size of gutter */
-
- 'getguides hinfo horizontal mpg right' /* get horizontal guide info */
- hcount=result /* number of horizontal guides*/
-
- 'getguides vinfo vertical mpg right' /* get vertical guide info */
- vcount=result /* number of vertical guides */
-
- usewidth=pgwidth-(lmar+rmar) /* useable width */
- useheight=pgheight-(tmar+bmar) /* useable height */
-
- colwidth=(usewidth-((colcnt-1)*cgut))/colcnt /* width of a columns */
-
- /**************************************************************************/
- /* Build arrays with all hguides and vguides */
- /**************************************************************************/
- /* Handle the horizontals */
- /**************************************************************************/
-
- hguide.0=0 /* init to NO horizontals */
- joff=0 /* for pointer control */
-
- if tmar~=0 then do /* has a top margin */
- hguide.1=tmar /* store top margin */
- joff=1 /* bump pointer to next */
- end
- do i=1 to hcount /* assume in order */
- j=joff+i /* entry to load */
- k=i-1 /* hinfo starts with 0 */
- hguide.j=hinfo.k /* load it */
- end
-
- if bmar~=0 then do /* we have a bottom margin */
- j=joff+i /* next entry slot */
- hguide.j=pgheight-bmar /* load it */
- end
-
- hguide.0=j /* save count of horizontals */
- hgidcnt=j /* save count of horizontals */
-
- /**************************************************************************/
- /* Handle vertical for columns first */
- /**************************************************************************/
-
- vguide.0=0 /* init to NO verticals */
- j=0 /* for pointer control */
- voff=0 /* offset for first vertical */
-
- if lmar~=0 then do /* has a left margin */
- vmargs.1=lmar /* store laft margin */
- voff=lmar /* add in left margin size */
- j=1 /* bump pointer to next */
- end
-
- if colcnt~=0 then do /* we have column definitions*/
- if cgut~=0 then do i=2 to (colcnt*2) /* non zero gutters */
- if i//2=0 then vpos=((i/2)*colwidth)+(((i/2)-1)*cgut)+voff
- else vpos= ((i-1)/2)*(colwidth+cgut)+voff
- if i/2=colcnt then do /* doing last vertical */
- if rmar~=0 then vpos=pgwidth-rmar /* use right margin value */
- end
- j=j+1 /* bump to next slot */
- vmargs.j=vpos /* store calculated values */
- vmargs.0=i /* running count of verts */
- end /* end of ~0 gutter columns */
- else do
- do i=1 to colcnt /* zero gutters between cols */
- vpos=i*colwidth+voff /* simple;) */
- if i=colcnt then do /* doing last vertical */
- if rmar~=0 then vpos=pgwidth-rmar /* use right margin value */
- end
- j=j+1 /* bump to next slot */
- vmargs.j=vpos /* store the value */
- end /* done with zero gutter cols*/
- end /* matches zero gutter else */
- end /* matches colcnt~=0 */
-
- vmargs.0=j /* save count for now */
- vgidcnt=j /* save count of verticals */
-
- /**************************************************************************/
- /* Now handle any vertical guides defined */
- /* */
- /* Possible conditions: */
- /* 1) Columns only defined - copy array */
- /* 2) Vertical page guides only defined - copy array as is */
- /* Vertical page guides with margins - copy array with margins */
- /* 3) Columns AND vertical page guides set - merge the two arrays */
- /* 4) NO verticals set - return with error */
- /* */
- /**************************************************************************/
-
- j=0 /* pointer control */
- select
- when vcount=0 & vgidcnt~=0 then do i=0 to vgidcnt
- vguide.i=vmargs.i
- j=i
- end
- when vcount~=0 & vgidcnt=0 then do i=1 to vcount
- j=j+1
- if i=1 & lmar~=0 then do
- vguide.1=lmar
- j=j+1
- end
- k=i-1
- vguide.j=vinfo.k
- if i=vcount & rmar~=0 then do
- j=j+1
- vguide.j=pagewidth-rmar
- end
- end
- when vcount~=0 & vgidcnt~=0 then do
- Call MergeVerts
- end
- otherwise do
- errmsg='This page has NO vertical guides or margins -- QUITTING'
- Call ErrorDisplay
- doneselecting=1 /* skip selecting */
- signal GetGuidesExit /* exit from routine */
- end
- end
-
- vguide.0=j /* final count of entries */
- vgidcnt=j /* save count of verticals */
-
- GetGuidesExit:
-
- Return
-
- /**************************************************************************/
- /* Merge the two vertical info arrays */
- /**************************************************************************/
- MergeVerts:
-
- j=1 /* ptr for vguide array */
- i=1 /* ptr for vmargs array */
- k=0 /* ptr for vinfo array */
- kdone=0 /* flag for when done */
- idone=0 /* flag for when done */
- do loop=1 /* loop until leave */
- select
- when kdone=1 & idone=1 then leave loop /* all merged - I hope:) */
- when kdone=1 & idone=0 then do
- vguide.j=vmargs.i
- j=j+1
- i=i+1
- if i>vgidcnt then idone=1
- end
- when kdone=0 & idone=1 then do
- vguide.j=vinfo.k
- j=j+1
- k=k+1
- if k=vcount then kdone=1
- end
- when vmargs.i > vinfo.k then do
- vguide.j=vinfo.k
- j=j+1
- k=k+1
- if k=vcount then kdone=1
- end
- when vinfo.k > vmargs.i then do
- vguide.j=vmargs.i
- j=j+1
- i=i+1
- if i>vgidcnt then idone=1
- end
- otherwise do /* must be equal - use 1 and bump all pointers */
- vguide.j=vmargs.i
- j=j+1
- i=i+1
- k=k+1
- if i>vgidcnt then idone=1
- if k=vcount then kdone=1
- end
- end
- end
-
- j=j-1 /* remove last increment */
-
- Return
-
- /**************************************************************************/
- /* Use guide arrays to build coords of each possible box */
- /* Mark which ones are true boxes and which are spacers */
- /**************************************************************************/
- BldCoords:
-
- if doneselecting=1 then signal BldCoordsExit /* skip all processing */
-
- hboxcnt=(vguide.0)-1 /* number of boxes across */
- vboxcnt=(hguide.0)-1 /* number of boxes down */
- bguide=hguide.hgidcnt /* bottom guide */
- rguide=vguide.vgidcnt /* right guide */
-
- /**************************************************************************/
- /* Load array with upper left coords for each box (ulx,uly) */
- /* Load array with lower right coord for each box (lrx,lry) */
- /* Load array with width and height for each box (w,h) */
- /* Flag each box as being a valid text size block or not (Y/N) */
- /* */
- /* Format of array: boxdesc.ulx.uly.lrx.lry.widht.height.flag */
- /* */
- /**************************************************************************/
-
- do i=1 to hboxcnt
- do j=1 to vboxcnt
- k=((i-1)*vboxcnt)+j /* box being handled */
- nexth=i+1 /* next horizontal guide */
- nextv=j+1 /* next vertical guide */
- boxdesc.k=vguide.i /* xcoord of top/left corner */
- boxdesc.k.1=hguide.j /* ycoord of top/left corner */
- if i=hboxcnt then boxdesc.k.1.1=rguide /* lower right xcoord */
- else boxdesc.k.1.1=vguide.nexth
- if j=vboxcnt then boxdesc.k.1.1.1=bguide /* lower right ycoord */
- else boxdesc.k.1.1.1=hguide.nextv
- boxdesc.k.1.1.1.1=boxdesc.k.1.1 - boxdesc.k /* width of box */
- boxdesc.k.1.1.1.1.1=boxdesc.k.1.1.1 - boxdesc.k.1 /* height of box */
- end
- end
-
- boxdesc.0=hboxcnt*vboxcnt /* number of possible boxes */
-
- BldCoordsExit:
-
- Return
-
- /**************************************************************************/
- /* this is where the boxes are selected */
- /**************************************************************************/
- SelectModel:
-
- if doneselecting=1 then signal SelectModelExit
-
- if refrchar=0 then do /* turn off display updates */
- 'refresh wait'
- end
-
- if mode='AUTO' then do
- targwidth=boxdesc.1.1.1.1.1 /* width of model box */
- targheight=boxdesc.1.1.1.1.1.1 /* height of model box */
- ulx=boxdesc.1 /* upper left x-coord */
- uly=boxdesc.1.1 /* upper left y-coord */
- midx=ulx+targwidth/2 /* xcoord middle of object */
- midy=uly+targheight/2 /* ycoord middle of object */
- 'selectobject at ' midx midy /* select object for id */
- end
- else do
- 'settoolmode object' /* turn on object tool */
- 'getcoord click message "Click in model text frame"'
-
- if rc~=0 then do /* user canceled requester */
- doneselecting=1 /* set flag */
- signal SelectModelExit /* need to quit */
- end
-
- 'selectobject at ' click.x click.y
-
- 'getobject type otype boundingbox selobj'
-
- if ~datatype(otype,'N') then do
- errmsg='You did not select a TEXT FRAME -- QUITTING'
- Call ErrorDisplay
- doneselecting=1 /* set flag */
- signal SelectModelExit /* need to quit */
- end
-
- ulx=selobj.left
- uly=selobj.top
- targwidth=selobj.right - selobj.left
- targheight=selobj.bottom - selobj.top
- end
-
- 'getobject type otype' /* get id of this text block */
- objid=result /* id is returned in result */
-
- if otype~=11 then do
- errmsg='This is not a text frame -- QUITTING'
- Call ErrorDisplay
- doneselecting=1 /* set flag */
- signal SelectModelExit /* need to quit */
- end
-
- 'selectobject none' /* have to free object */
-
- midx=ulx+targwidth/2 /* xcoord middle of object */
- midy=uly+targheight/2 /* ycoord middle of object */
-
- 'settoolmode text' /* change to text mode */
- 'selecttext at 'midx midy /* select text in first box */
- 'selecttext at 'midx midy ' all' /* select text in first box */
- 'getarticlewordcount' /* get number of words */
- wordcount=result
-
- if wordcount=0 then do
- errmsg='NO text in this block -- QUITTING'
- Call ErrorDisplay
- doneselecting=1 /* set flag */
- signal SelectModelExit /* need to quit */
- end
-
- 'exporttext file 'importfile 'filter ascii amiga textcode pagestream force'
- 'cuttext' /* delete the text */
- 'settoolmode object' /* change to object mode */
- 'deleteobject objectid' objid /* delete the text frame obj */
-
- matchboxes=0 /* boxes matching model */
-
- do i=1 to boxdesc.0
- testwidth=boxdesc.i.1.1.1.1 /* width of box being tested */
- testheight=boxdesc.i.1.1.1.1.1 /* height of box being tested */
- widthvar=abs(targwidth-testwidth)/targwidth /* variance in width */
- heightvar=abs(targheight-testheight)/targheight /* variance in height */
- if widthvar<=pctvar & heightvar<=pctvar then do
- boxdesc.i.1.1.1.1.1.1='Y'
- matchboxes=matchboxes+1 /* one more found */
- end
- else boxdesc.i.1.1.1.1.1.1='N'
- end
-
- if matchboxes=0 then do /* no matches found */
- errmsg='NO text blocks match Model - QUITTING'
- Call ErrorDisplay
- doneselecting=1 /* set flag */
- signal SelectModelExit /* need to quit */
- end
-
- SelectModelExit:
-
- Return
-
- /**************************************************************************/
- /* */
- /* Build all boxes and fill with modified text */
- /* */
- /**************************************************************************/
- BldBoxes:
-
- if doneselecting=1 then signal BldBoxesExit
-
- validboxes=0
- impstring.=' '
- impcnt=0
-
- goodopen=open('IMPX',importfile,'R')
- if ~goodopen then do
- errmsg='Could not open 'importfile' for input -- QUITTING'
- Call ErrorDisplay
- doneselecting=1 /* set flag */
- signal BldBoxesExit
- end
-
- do until eof('IMPX') /* read until end of file */
- impcnt=impcnt+1 /* next import/export record */
- impstring.impcnt=readln('IMPX') /* read next record */
- end /* matches until EOF */
-
- result=close('IMPX') /* close the import file */
-
- /**************************************************************************/
- /* This is where we need to control the number of pages */
- /**************************************************************************/
-
- pagecnt=datacnt%matchboxes /* how many whole pages */
- pagepart=datacnt//matchboxes /* partial pages */
- if pagepart~=0 then pagecnt=pagecnt+1 /* handle extra records */
- dataptr=0 /* initialize data pointer */
-
- openbusyrequester message 'Processing...' thermometer abort enabled total datacnt current 0
- bh=result /* pointer to requester */
- bhopen=1 /* set a flag for later */
-
- do pagenum=1 to pagecnt /* end of loop is within code */
- do i=1 to boxdesc.0 /* loop thru box definitions */
- if boxdesc.i.1.1.1.1.1.1='Y' then do /* need to draw this one */
- ulx=boxdesc.i
- uly=boxdesc.i.1
- lrx=boxdesc.i.1.1
- lry=boxdesc.i.1.1.1
- 'drawcolumn ' ulx uly lrx lry column 1
- validboxes=validboxes+1
- 'selecttext at ' ulx uly
- dataptr=dataptr+1
- Call ChangeText
- if doneselecting=1 then signal BldBoxesExit /* something went wrong */
- 'inserttext file ' importfile 'filter ascii amiga textcode pagestream'
- getbusyrequester bh /* test for abort */
- if result=1 then do
- doneselecting=1 /* indicate time to quit */
- signal BldBoxesExit
- end
- else setbusyrequester bh current dataptr
- if dataptr=datacnt then leave pagenum /* all data recs processed */
- if validboxes=matchboxes then do /* is it end of a full page ? */
- i=999999 /* force end of boxdesc loop */
- validboxes=0 /* reset boxes drawn on page */
- 'Display page next' /* go to next page */
- end /* matches end of page */
- end /* matches boxdesc='Y' */
- end /* matches do i=1 to boxdesc.0*/
- end
-
- 'Display page 1' /* go to page 1 */
-
- if mode='AUTO' then do /* check mode again */
- doneselecting=1 /* only do once */
- end
-
- if refrchar=0 then do /* refresh page 1 display */
- 'refresh continue'
- end
-
- BldBoxesExit:
-
- if bhopen=1 then do /* busy req is open */
- closebusyrequester bh /* close it */
- bhopen=0 /* show we closed it */
- end
-
- Return
-
- /**************************************************************************/
- /* */
- /* Change copy of exported text, rewrite export file */
- /* !!! Don't use variable 'i' within this routine !!! */
- /**************************************************************************/
- ChangeText:
-
- do j=1 to impcnt
- impcopy.j=impstring.j
- end
-
- /**************************************************************************/
- /* Here is the actual change code */
- /* (what a lot of work to get here;)) */
- /**************************************************************************/
-
- do j=1 to impcnt /* loop thru copy of text */
- do varptr=1 to varcnt
- repvar=varname.varptr /* search string */
- replen=length(repvar) /* replacement length */
- do varloop=1
- varpos=pos(repvar,impcopy.j) /* look for variable to rep. */
- if varpos~=0 then do
- repstr1=substr(impcopy.j,1,varpos-1) /* part before variable */
- repstr2=substr(impcopy.j,varpos+replen) /* part after it */
- impcopy.j=repstr1||datavar.dataptr.varptr||repstr2
- end
- else leave varloop
- end
- end
- end
-
- goodopen=open('IMPX',importfile,'W')
- if ~goodopen then do
- errmsg='Could not open 'importfile' for output -- QUITTING'
- Call ErrorDisplay
- doneselecting=1 /* set flags */
- Signal ChangeTextExit
- end
-
- do j=1 to impcnt /* write array back to file */
- foo=writeln('IMPX',impcopy.j) /* write next record */
- end
-
- result=close('IMPX') /* close the export file */
-
- ChangeTextExit:
-
- Return
-
- /**************************************************************************/
- /* */
- /* Read in the information from the .prefs file */
- /* */
- /**************************************************************************/
- ReadPrefs:
- goodopen=open('Prefs',prefsfile,'R')
- if ~goodopen then do
- errmsg='Could not open Prefs file -- using Defaults'
- Call ErrorDisplay
- end
- else do
- do until eof('Prefs')
- pref=readln('Prefs')
- if pref~=' ' & pref~='#' & pref~='' then do
- if pos('#',pref)~=1 then do
- if pos('#',pref)>2 then do
- pref=substr(pref,1,pos('#',pref)-1)
- end
- pref=strip(pref)
- interpret pref
- end
- end
- end
- end
- result=close('Prefs')
-
- Return
-
- /**************************************************************************/
- /* */
- /* Load PageStream file */
- /* */
- /**************************************************************************/
- LoadPGS:
-
- if doneselecting=1 then signal LoadPGSExit /* error or cancel */
-
- 'open ' "'"templatefile"'"
- if rc~=0 then do
- errmsg='Unable to open PageStream file: 'le||le||templatefile
- CALL ErrorDisplay
- doneselecting=1
- end
-
- LoadPGSExit:
-
- Return
-
- /**************************************************************************/
- /* */
- /* Read the Data file into array */
- /* */
- /**************************************************************************/
- OpenData:
-
- if doneselecting=1 then signal OpenDataExit /* error or cancel */
-
- varcnt=1 /* assume we'll have a header */
- goodopen=open('Data',datafile,'R')
- if ~goodopen then do
- errmsg='Could not open data file: 'le||le||datafile
- Call ErrorDisplay
- doneselecting=1
- signal OpenDataExit
- end
-
- if lvind='<' then do /* handle PGS escape coding */
- lvind='<\<>'
- rvind='<\>>'
- end
-
- ReadHeader:
-
- headln=readln('Data')
- delimpos=pos(datadelim,headln) /* find first delimiter */
- do while delimpos~=0 /* loop across header record */
- rawvar=substr(headln,1,delimpos-1) /* variable name */
- rawvar=strip(rawvar) /* strip blanks */
- varname.varcnt=lvind||rawvar||rvind /* concat with indicators */
- headln=substr(headln,delimpos+1) /* shorten remainin data rec */
- delimpos=pos(datadelim,headln) /* find next delimiter */
- varcnt=varcnt+1 /* increment counter */
- end
- rawvar=headln /* last variable name */
- rawvar=strip(rawvar) /* strip blanks */
- varname.varcnt=lvind||rawvar||rvind /* concat with indicators */
- varname.0=varcnt /* store variable count */
-
- if varcnt=1 & (headln='' | headln=' ') then do /* no header info */
- errmsg='NO header found in data file -- QUITTING'
- Call ErrorDisplay
- doneselecting=1
- signal OpenDataExit
- end
-
- ReadData:
-
- do until eof('Data') /* read until end of file */
- dataln=readln('Data') /* read next record */
- if dataln~='' then do /* skip null records */
- datacnt=datacnt+1 /* record count being done */
- do i=1 to varcnt /* parse values from data rec */
- delimpos=pos(datadelim,dataln) /* location of delimiter char */
- if delimpos~=0 then do /* found a delimiter */
- datavar.datacnt.i=substr(dataln,1,delimpos-1)
- dataln=substr(dataln,delimpos+1) /* shorten data record */
- end
- else do
- datavar.datacnt.i=dataln /* use remainder of record */
- end
- end /* matches i=1 to varcnt */
- end /* matches non null record */
- end /* matches until EOF */
-
- datavar.0=datacnt /* store count of records */
- result=close('Data') /* close the data file */
-
-
- FixData:
-
- do i=1 to datavar.0 /* loop thru each data record */
- do j=1 to varcnt /* for each variable */
- spos=1 /* start of string position */
- tpos=verify(datavar.i.j,'<>@\','MATCH') /* chars to escape */
- do while tpos>0 /* if found escape it */
- datavar.i.j=insert('>',datavar.i.j,spos+tpos-1)
- datavar.i.j=insert('<\',datavar.i.j,spos+tpos-2)
- spos=spos+tpos+3 /* position after this one */
- tpos=verify(substr(datavar.i.j,spos),'<>@\','MATCH')
- end
- end
- end
-
-
- OpenDataExit:
-
- Return
-
- /**************************************************************************/
- /* */
- /* Setup variables, lists, etc. */
- /* */
- /**************************************************************************/
- Init:
-
- le=d2c(10) /* line end text displaying */
-
- delimstem.0=3 /* change this if add delimieters */
- delimstem.1='Comma' /* name of character */
- delimstem.1.1=',' /* character itself */
- delimstem.2='Tab'
- delimstem.2.1=d2c(09)
- delimstem.3='SemiColon'
- delimstem.3.1=';'
-
- defaultdelim=0 /* default data delimiter */
-
- vindstem.0=4 /* number of pairs -- change this if add var indicators */
- vindstem.1='<' /* left indicator of pair */
- vindstem.1.1='>' /* right indicator of pair */
- vindstem.2='«' /* left indicator of pair */
- vindstem.2.1='»' /* right indicator of pair */
- vindstem.3='[' /* left indicator of pair */
- vindstem.3.1=']' /* right indicator of pair */
- vindstem.4='{' /* left indicator of pair */
- vindstem.4.1='}' /* right indicator of pair */
-
- defaultvind=0 /* default variable indicator */
-
- varname.=' ' /* initialize var names to blank */
- varname.0=0 /* initialize variable count to 0 */
- varcnt=0 /* initialize to NO variable names */
-
- datavar.=' ' /* initialize var fields to blanks */
- datavar.0=0 /* initialize record count to zero */
- datacnt=0 /* initialize to NO data records */
-
- pctvar=.10 /* allow 10% variance in box sizes */
-
- mode='AUTO' /* default to automatic handling */
- defaultmode="True" /* Automatic mode of processing */
-
- defaultwatchme="True" /* default to screen refreshing */
-
- datapath='PageStream3:' /* use PGS3 path for requesters */
- datafile='' /* init to missing */
- templatepath='PageStream3:' /* use PGS3 path for requesters */
- templatefile='' /* init to missing */
- importfile="T:LabelMerge.import" /* name of temporary file */
-
- doneselecting=0 /* haven't finished selections yet */
- bhopen=0 /* no busy requester yet */
-
- errmsg='' /* no errors to start with */
-
- /**************************************************************************/
- /* Internal Help Information for Label Merge Program */
- /* */
- /* each group can be no longer than 255 characters */
- /* this is roughly 6 complete lines of help text */
- /**************************************************************************/
-
- helppages=9 /* number of pages of help info */
-
- helpmsg.1='See LabelMerge.readme for complete details'le||le||,
- 'Prior to using this script you must create',
- 'a PAGESTREAM TEMPLATE file that describes',
- 'the label sheet you are going to print.'le||le||,
- 'Each print area must be bounded by guides',
- 'and have a model text frame defined.'
-
- helpmsg.2='The text allows variables using any of',
- 'these pairs: < >, « », [ ], or { }'le||le||,
- 'The « » pair can be produced using',
- 'Alt-9 and Alt-0 keys.'le||le'The default indicators',
- 'are < >.'le||le'Example: <name> <addr> etc.'le||le||,
- 'Only one type is allowed within a single template.'
-
- helpmsg.3='The DATA FILE requires a header with the',
- 'variable names separated by the delimiter set in the',
- 'FIELD DELIMITER gadget'le||le||,
- 'The remaining records contain the data that will replace',
- 'the variables in the template'le||le||,
- 'Each data field must be separated by the DELIMITER.'
-
- helpmsg.4='The built in options for DELIMITER are:'le||le||,
- 'COMMA'le||le||,
- 'TAB'le||le||,
- 'SEMI-COLON'le||le||,
- 'The default is COMMA'
-
- helpmsg.5='The AUTO option expects only ONE text',
- 'frame type in the template and that the model is the',
- 'TOP LEFT text frame.'le||le||,
- 'Turning AUTO OFF allows for multiple sizes of text frames',
- 'and for a template that does not match the expected',
- 'default.'
-
- helpmsg.6='The WATCH-ME-WORK option shows you all',
- 'of the processing as it takes place.'le||le||,
- 'Turning it off limits the number of screen refreshes.'le||le||,
- 'On my A4000/040 this is about 14% faster.'
-
- helpmsg.7='The FUZZINESS value controls how close',
- 'a bounded area must be to the model to be considered as a match.'le||le||,
- 'A target must be within this variance in',
- 'width and height.'le||le||'The default is .10'
-
- helpmsg.8='IN CASE OF EMERGENCY:'le||le||,
- 'If you must STOP LabelMerge in the midst of processing'le||le||,
- '1) Switch to WorkBench'le||le||,
- '2) Open a CLI window'le||le||,
- '3) Enter <HI> (without the brackets) and it should quit shortly'
-
- helpmsg.9='For BUG reports, comments, etc.'le||le||,
- 'Contact:'le||le||,
- 'Dick Whiting'le||le||,
- 'email: dwhiting@europa.com'le||le||,
- 'If you use and LIKE this effort, my kids would REALLY love a',
- 'postcard from where ever you live'le||le||,
- '28590 S. Beavercreek Rd.'le||,
- 'Mulino, Oregon 97042'le||,
- 'USA'
-
- Return
-
- /**************************************************************************/
- /* */
- /* Display HELP information */
- /* */
- /**************************************************************************/
- HelpDisplay:
-
- allocarexxrequester '"Label Merge Help Information"' 400 200
- handle.helpreq=result
-
- addarexxgadget handle.helpreq MULTILINE 10 10 380 160 BORDER none STRING ' '
- helpmsghandle=result
-
- addarexxgadget handle.helpreq EXIT 10 180 70 label "_More"
- morehandle=result
-
- addarexxgadget handle.helpreq EXIT 320 180 70 label "_Cancel"
- hcancelhandle=result
-
- do hshow=1 to helppages
-
- setarexxgadget handle.helpreq helpmsghandle STRING '"'helpmsg.hshow'"'
-
- if hshow=helppages then do
- setarexxgadget handle.helpreq morehandle label "_Again"
- end
- else do
- setarexxgadget handle.helpreq morehandle label "_More"
- end
-
- doarexxrequester handle.helpreq
- haction=result
-
- if haction=hcancelhandle then leave hshow
- if hshow=helppages & haction=morehandle then hshow=0
-
- end
-
- freearexxrequester handle.helpreq
-
- Return
- /**************************************************************************/
- /* */
- /* Display ERROR information */
- /* */
- /**************************************************************************/
- ErrorDisplay:
-
- errmsg=errmsg||le||le||'See LabelMerge.readme for usage details'
-
- allocarexxrequester '"Label Merge ERROR Information"' 400 200
- handle.errreq=result
-
- addarexxgadget handle.errreq MULTILINE 10 10 380 160 BORDER none STRING '"'errmsg'"'
- errmsghandle=result
-
- addarexxgadget handle.errreq EXIT 165 180 70 label "_Done"
- donehandle=result
-
- doarexxrequester handle.errreq
- haction=result
-
- freearexxrequester handle.errreq
-
- Return
-
-